package jack.code.hnzb.service;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.Scanner;

/**
 * Created by LiJiakui on 17/7/24.
 */
public class WanMeisj {

    /**
     * 获取内容  http://wanmeishijiexiaoshuo.org/book/1134.html
     * @return
     * @throws IOException
     */
    public static String getTest(String url) throws IOException {
        //分页
        int pageNo = 0;
        int pageStart;
        Scanner scanner = new Scanner(System.in);
        Document document = Jsoup.connect(url).timeout(6000).get();
        Elements dev = document.getElementsByClass("bg");
        Elements h1 = dev.get(0).getElementsByTag("h1");
        Elements p = dev.get(0).getElementsByTag("p");
        System.out.println(h1.get(0).text());
        int i= 1;
        while (i!=0){
            i= scanner.nextInt();
            if(i == 0){
                break;
            }
            if(i == 1){
                pageNo++;
            }
            if(i == 2){
                pageNo--;
            }
            try {
                pageStart = (pageNo-1)*3;
                System.out.println(p.get(pageStart).text());
                System.out.println(p.get(pageStart+1).text());
                System.out.println(p.get(pageStart+2).text());
            } catch (Exception e) {
                pageNo = 0;
            }
        }
        return null;
    }

    public static void main(String[] args) throws IOException {
        WanMeisj.getTest("http://wanmeishijiexiaoshuo.org/book/1189.html");
//        Scanner scanner = new Scanner(System.in);
//        for(int i=0; i<100; i++){
//            int x = scanner.nextInt();
//            System.out.println(x);
//        }
    }
}
